package us.icitap.commandcenter.ui.dispatcher;

import us.icitap.commandcenter.CommandCenterUI;
import us.icitap.commandcenter.business.Result;
import us.icitap.commandcenter.business.ejb.persistence.Call;
import us.icitap.commandcenter.business.ejb.persistence.Officer;
import us.icitap.commandcenter.business.ejb.persistence.OrgStructure;
import us.icitap.commandcenter.business.ejb.persistence.UniqueNumber;
import us.icitap.commandcenter.listeners.ManageCallListener;
import us.icitap.commandcenter.ui.custom.ButtonsLayout;
import us.icitap.commandcenter.ui.custom.CustButton;
import us.icitap.commandcenter.ui.custom.CustTextArea;
import us.icitap.commandcenter.ui.custom.CustTextField;
import us.icitap.commandcenter.utils.HandleNotification;
import us.icitap.commandcenter.utils.OfficerComponent;

import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.vaadin.ui.Button.ClickEvent;

public class UniqueNumberWindow extends Window{

	 
	
	private final CustTextArea unNotesTextArea = new CustTextArea("Shenime mbi numrin unik");
	
	private final CustButton createButton = new CustButton("Krijo numer unik");
	
	private Officer selectedOfficer;
	
	private OrgStructure orgStructure;
	
	private ManageCallListener manageCallListener;
	private  Call call;
	
	private OfficerComponent officerComponent = new OfficerComponent();
	
	public UniqueNumberWindow(final ManageCallListener manageCallListener,  Call call) {
	
		this.manageCallListener = manageCallListener;
		this.call = call;
		
		this.setModal(true);
		this.setResizable(false);
		this.center();
		
		this.setCaption("Krijimi i numrit unik");
		
		final VerticalLayout vl = new VerticalLayout();
		vl.setMargin(true);
		vl.setSpacing(true);
		
		
//		vl.addComponent(new OfficerComponent("9012345, Zyhdi Mema", "DREJTORIA E PERPUNIMIT DHE MBROJTJES SE TE DHENAVE"));
		vl.addComponent(officerComponent);
			
		vl.addComponent(unNotesTextArea);
		unNotesTextArea.setWidth("500px");
		
		final ButtonsLayout buttonsLayout = new ButtonsLayout("500px");
		buttonsLayout.addComponent(createButton);
		buttonsLayout.setComponentAlignment(createButton, Alignment.MIDDLE_RIGHT);
		vl.addComponent(buttonsLayout);
				
		this.setContent(vl);
		
		this.createButton.addClickListener(new ClickListener() {
			
			@Override
			public void buttonClick(ClickEvent event) {
				UniqueNumber un = new UniqueNumber();
				un.setRecordUser(CommandCenterUI.getUser().getUsername());
				un.setRequestingOfficer(selectedOfficer);
				un.setDescription(unNotesTextArea.getValue());
				UniqueNumberWindow.this.call.setUniqueNumber(un);
				
				manageCallListener.generateUniqueNumber(UniqueNumberWindow.this.call);
				
				
			}
		});
		
		
		
	}

	public void setCall(Call call) {
		officerComponent.setOfficer("", "");
		this.call = call;
		
	}
	
}
